<template>
	<div class="report-container">
		<!-- 审核确认弹框 -->
		<AuditConfirm ref="auditDialog" :submit="auditOne" />
		<div class="review-content">
			<div class="head">
				<span class="title">
					{{ $t('member.details_of_new_member_review') }}
				</span>
				<div v-if="type" class="right-btn">
					<el-button plain @click="goBack">
						{{ $t('common.cancel') }}
					</el-button>
					<el-button type="success" @click="() => $refs.auditDialog.successOpen()">
						{{ $t('member.approved') }}
					</el-button>
					<el-button type="danger" @click="() => $refs.auditDialog.dangerOpen()">
						{{ $t('member.audit_ejection') }}
					</el-button>
				</div>
				<div v-else class="right-btn">
					<el-button plain @click="goBack">
						{{ $t('common.back') }}
					</el-button>
				</div>
			</div>
			<div class="main-content detailBoxStyle">
				<div class="review-content">
					<p class="name">
						{{ $t('member.new_member_information_details') }}
					</p>
					<div class="review-flex">
						<div>
							{{ $t('common.number_type') }}:
							{{ typeFilter(list.accountType, 'accountType') }}
						</div>
						<div>
							{{ $t('common.belong_merchant') }}:
							{{ merchantFilter(list.merchantId) || '-' }}
						</div>
						<div>
							{{ $t('common.top_agent') }}:
							{{ list.parentProxyName }}
						</div>
					</div>

					<div class="review-flex">
						<div>
							{{ $t('member.belong_club') }}:
							{{ list.clubName || '-' }}
						</div>

						<div>
							{{ $t('common.member_number') }}:
							{{ list.userName || '-' }}
						</div>

						<div>
							{{ $t('common.business_model') }}:
							{{
								mappingBusinessModel(list.businessModel) || '-'
							}}
						</div>
					</div>

					<div class="review-flex">
						<div class="reason">
							<p>{{ $t('member.password') }}:</p>
							<span>
								{{ list.password || '-' }}
							</span>
						</div>
						<div>
							{{ $t('member.nickname') }}:
							{{ list.userName || '-' }}
						</div>
						<div>
							{{ $t('member.gender') }}:
							{{ typeFilter(list.gender, 'genderType') }}
						</div>
						<!-- <div>
							{{ $t('common.vip_level') }}:
							{{ 'VIP' + list.vipLevel }}
						</div> -->
					</div>
					<div class="review-flex">
						<div>
							安全校验: {{ checkTypes[list.checkType] || '-'}}
						</div>
					</div>
				</div>
				<div class="review-content">
					<p class="name">{{ $t('member.apply_info') }}</p>
					<div class="review-flex">
						<div>
							{{ $t('member.applicant') }}:
							{{ list.applyName || '-' }}
						</div>
						<div>
							{{ $t('member.application_time') }}:
							{{ list.createdAt || '-' }}
						</div>
						<div class="show-remark">
							{{ $t('member.apply_info') }}:
							{{ list.applyRemark || '-' }}
						</div>
					</div>
				</div>
				<div class="review-content">
					<p class="name">{{ $t('member.audit_information') }}</p>
					<div class="review-flex">
						<div v-if="list.auditStatus === 1">
							{{ $t('member.reviewed_by') }}: -
						</div>
						<div v-else>
							{{ $t('member.reviewed_by') }}:
							{{ list.auditName || '-' }}
						</div>
						<div>
							{{ $t('member.audit_time') }}:
							{{ list.auditDatetime || '-' }}
						</div>
						<div class="show-remark">
							{{ $t('member.review_remarks') }}:
							{{ list.auditRemark || '-' }}
						</div>
					</div>
				</div>
			</div>
		</div>
		<el-dialog
			:title="`${$t('member.submit_for_confirmation')}`"
			center
			:visible.sync="visible"
			:before-close="closeFormDialog"
			width="610px"
			class="audit-confirm"
		>
			<el-form
				ref="form"
				:model="form"
				:rules="formRules"
				label-width="120px"
			>
				<el-form-item
					v-if="action"
					:label="`${$t('member.submit_audit_information')}:`"
					prop="remark"
				>
					<el-input
						v-model.trim="form.remark"
						clearable
						type="textarea"
						:maxlength="500"
						show-word-limit
						:autosize="{ minRows: 4, maxRows: 4 }"
						style="width: 380px"
						:placeholder="$t('common.please_enter')"
						@input="handleInput"
					></el-input>
				</el-form-item>
				<el-form-item
					v-else
					:label="`${$t('member.submit_audit_information')}:`"
					prop="remark"
				>
					<el-input
						v-model.trim="form.remark"
						clearable
						type="textarea"
						show-word-limit
						:maxlength="500"
						:autosize="{ minRows: 4, maxRows: 4 }"
						style="width: 380px"
						:placeholder="$t('common.please_enter')"
						@input="handleInput"
					></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="visible = false">
					{{ $t('common.cancel') }}
				</el-button>
				<el-button type="primary" @click="auditOne">
					{{ $t('common.submit') }}
				</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import list from '@/mixins/list'
import { routerNames } from '@/utils/consts'
import { NO_SPECIAL_CHAR } from '@/utils/pattern'
// import dayjs from 'dayjs'
import AuditConfirm from '@/components/AuditConfirm'

export default {
	name: routerNames.addMemberReview,
	components: {
		AuditConfirm
	},
	mixins: [list],
	props: {
		// 审核 true 仅返回 false
		type: Boolean,
		rowData: {
			type: Object,
			default: () => {}
		}
	},
	data() {
		this.auditOne = this.throttle(this.auditOne, 1000)
		return {
			list: {},
			checkTypes: {
				0: '无校验',
				1: '身份验证器',
				2: '邮箱校验',
				3: '手机校验'
			},
			visible: false,
			form: {
				remark: ''
			},
			action: false
		}
	},
	computed: {
		formRules() {
			return {
				remark: [
					{
						required: true,
						message: this.$t('member.greater_than2'),
						trigger: 'blur'
					},
					{
						min: 2,
						max: 500,
						message: this.$t('member.greater_than2'),
						trigger: 'blur'
					}
				]
			}
		}
	},
	created() {
		this.getInfo()
	},
	mounted() {},
	methods: {
		handleInput(val) {
			this.form.remark = val.replace(NO_SPECIAL_CHAR, '')
		},
		closeFormDialog() {
			this.$refs.form.resetFields()
			this.visible = false
		},
		confirm(action) {
			this.form.remark = undefined
			this.$nextTick(() => {
				this.$refs.form.clearValidate()
			})
			this.action = action
			this.visible = true
		},
		auditOne(form) {
			const params = {
				id: this.rowData.id,
				userId: this.rowData.userId,
				remark: form.remark,
				auditStatus: form.status,
				checkType: this.list.checkType
			}
			const loading = this.$loading({
				lock: true,
				text: 'Loading',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			})
			this.$api
				.updateMemberAuditRecord(params)
				.then((res) => {
					loading.close()
					if (res.code === 200) {
						this.$message({
							type: 'success',
							message: this.$t(
								'common.action_success'
							)
						})
						this.visible = false
						this.goBack()
					} else {
						this.$message({
							message: res.msg,
							type: 'error'
						})
					}
				})
				.catch(() => {
					loading.close()
				})
		},
		goBack() {
			this.$emit('goBack')
		},
		getInfo() {
			const params = {
				id: this.rowData.id
			}
			this.$api.memberAuditDetail(params).then((res) => {
				if (res.code === 200) {
					const response = res.data
					this.loading = false
					this.list = response
				} else {
					this.loading = false
					this.$message({
						message: res.msg,
						type: 'error'
					})
				}
			})
		}
	}
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__header {
	text-align: center;
	color: #909399;
	font-weight: 700;
}
.review-content {
	.head {
		height: 70px;
		line-height: 70px;
		width: 100%;
		background: #000;
		border-radius: 2px;
		padding: 0 30px;
		.title {
			font-weight: 600;
			color: rgb(192, 190, 190);
		}
		.right-btn {
			float: right;
		}
	}
	.main-content {
		.review-content {
			min-height: 150px;
			border-top: 0px;
			padding: 30px;
			.name {
				font-weight: 600;
			}
			.review-flex {
				display: flex;
				justify-content: space-between;
				width: 100%;
				margin-top: 20px;
				div {
					width: 33%;
					word-break: break-all;
				}
				.show-remark {
					word-wrap: break-word;
					vertical-align: top;
				}
			}
		}
		.more-height {
			height: 200px;
		}
	}
}
.reason {
	display: flex;
	p {
		min-width: 70px;
		padding-right: 5px;
	}
	span {
		word-break: break-all;
	}
}
</style>
